home *** CD-ROM | disk | FTP | other *** search
/ Maplin Electronics Catalogue 2001 Winter / Maplins Catalogue Winter 2001.iso / JScript / CustD.js < prev    next >
Text File  |  2000-11-07  |  17KB  |  413 lines

  1. // **********************************************************************
  2. // *     CustDetail.js JavaScript Development by Burgeonet.com          * 
  3. // *                Development Started 12-10-2000                      *
  4. // **********************************************************************
  5.  
  6. // ---====**** Begin code section for Customer Detail display ****====---
  7.  
  8. // **********************************************************************
  9. // * Establish array variables. These must match the                     *
  10. // * Customer Detail Variables as per the CustDetail.htm page.          *
  11. // *                                                                     *
  12. // *  Mr/Mrs/Miss/Ms        Salute                                         *
  13. // *  First name            FirstName                                     *
  14. // *  Initials                Initials                                     *
  15. // *  Last Name                LastName                                     *
  16. // *  Company Name            Comp Name                                     *
  17. // *  Address                Address                                         *
  18. // *  Address2                Address2                                     *
  19. // *  Post Code                PoCode                                         *
  20. // *  Telephone                CustTele                                    *
  21. // *                                                                     *
  22. // *                             1 2 3 4 5 6 7 8 9 10 11 12 13              *
  23. // *   Delimitor characters     ñ ª º ½ ¼ ║ ╗ ┐ ╢  ▐     °  ^               *
  24. // *                                                                    *
  25. // **********************************************************************
  26.       
  27. var Salute    = new Array();
  28. var FirstName    = new Array();
  29. var Initials    = new Array();
  30. var LastName    = new Array();
  31. var CompName    = new Array();
  32. var Address        = new Array();
  33. var Address2    = new Array();
  34. var PoCode        = new Array();
  35. var CustTele    = new Array();
  36.  
  37.  
  38.  
  39.  
  40. // -----------------------------  End  ----------------------------------
  41.  
  42. //          ----====****Begin shared cookie functions****====----
  43.  
  44. // **********************************************************************
  45. // *            Global expdate variable for cookies                        *
  46. // *               Cookie is set to expire in 24 hours                  *
  47. // **********************************************************************
  48.  
  49. var expdate = new Date();
  50. expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000))
  51.  
  52. // -----------------------------  End  ----------------------------------
  53.  
  54. // **********************************************************************
  55. // *                        Read cookie data.                           *
  56. // **********************************************************************
  57.  
  58. function getCookieData(name) {
  59.     var label = name + "="
  60.     var labelLen = label.length
  61.     var cLen = document.cookie.length
  62.     var i = 0
  63.     while (i < cLen) {
  64.         var j = i + labelLen
  65.         if (document.cookie.substring(i,j) == label) {
  66.             var cEnd = document.cookie.indexOf(";",j)
  67.             if (cEnd == -1) {
  68.                 cEnd = document.cookie.length
  69.             }
  70.             return unescape(document.cookie.substring(j,cEnd))
  71.         }
  72.         i++
  73.     }
  74.     return ""
  75. }
  76.  
  77. // -----------------------------  End  ----------------------------------
  78.  
  79.  
  80. // **********************************************************************
  81. // *                        Write cookie data.                            *
  82. // **********************************************************************
  83.  
  84. function setCookieData(name,value,expires) {
  85.         counter ++
  86.     document.cookie = name + "=" + counter + "@" + value + "; expires=" 
  87.                    + expires + "; Path=" + "/"
  88. }
  89.  
  90. // -----------------------------  End  ----------------------------------
  91.  
  92.  
  93. // **********************************************************************
  94. // *                     Kill cookie function.                          *
  95. // **********************************************************************
  96.  
  97. function killCookie(name) {
  98.  if (getCookieData(name)) {
  99.  document.cookie = name + "=" + "; expires = Thu, 01-Jan-70 00:00:01 GMT" 
  100.             + ";path = /"
  101.  cookData = ""
  102.  counter = 0
  103.  //history.go(0)
  104.  }
  105. }
  106.  
  107. // -----------------------------  End  ----------------------------------
  108.  
  109. //          ----====**** End shared cookie functions ****====----
  110.  
  111. // **********************************************************************
  112. // *               Begin code section to update the cookie to           *
  113. // *              add items to the shopping cart cookie 'Scart'.        *
  114. // **********************************************************************
  115.  
  116. //            ----====**** Global variables. ****====----
  117.  
  118. var counter = 0
  119. var cookData = ""
  120.  
  121. // **********************************************************************
  122. // *           Extract current value of cookie when page loads          *
  123. // *            and store the values in the global variables.           *
  124. // **********************************************************************
  125.  
  126. if (getCookieData("Detail")) {
  127.  
  128.  orderString = getCookieData("Detail")
  129.  cLen = orderString.length
  130.  countEnd = orderString.indexOf("@")
  131.  pointer = countEnd + 1
  132.  counter = orderString.substring(0,countEnd)
  133.  cookData = orderString.substring(pointer,cLen)
  134. }
  135.  
  136. // -----------------------------  End  ----------------------------------
  137.  
  138. // **********************************************************************
  139. // *        Function to add details to the Details Cookie.              *
  140. // *      To ensure that there is only ever one set of details          *
  141. // *   any previous cookie is deleted before the new info is applied    *
  142. // **********************************************************************
  143.  
  144. function addinfo() {
  145. killCookie("Detail")
  146. addDetail = '' + Salute + '¼' + FirstName 
  147.         + '║' + Initials + '╗' + LastName + '┐' + CompName + '╢' + Address + '▐' + Address2 
  148.         + ' ' + PoCode + '°' +  CustTele  + '^'
  149. //addCart = '' + a + '`' + itemDesc[num] + '~' + price[num] + '½' + itemQty[num] + '^'
  150. cookData += eval("addDetail")
  151.  
  152. if (confirm("Add Details to Cookie")) {
  153.   setCookieData("Detail", cookData, expdate.toGMTString())
  154. }
  155. }
  156.  
  157. // -----------------------------  End  ----------------------------------
  158.  
  159. //  ----====**** End code section for updating the cookie. ****====----
  160.  
  161. // **********************************************************************
  162. // *            Debugging function to display cookie contents.            *
  163. // **********************************************************************
  164.  
  165. function showMe() {
  166. if (getCookieData("Detail") == "") 
  167. alert("Cookie Blank"); 
  168. else {
  169. alert("ShowMe" + getCookieData("Detail")); 
  170.  }
  171. }
  172. // -----------------------------  End  ----------------------------------
  173.  
  174. // **********************************************************************
  175. // *            Builds an array of the items to load the cart.          *
  176. // **********************************************************************
  177.  
  178. function orderDetail(Idx,Sal,Fir,Ini,Lnm,Com,Adda,Addb,Pcde,Ctel) {
  179. Salute[Idx]    = Sal
  180. FirstName[Idx]    = Fir    
  181. Initials[Idx]    = Ini    
  182. LastName[Idx]    = Lnm    
  183. CompName[Idx]    = Com    
  184. Address[Idx]    = Adda        
  185. Address2[Idx]    = Addb    
  186. PoCode[Idx]        = Pcde        
  187. CustTele[Idx]    = Ctel    
  188.  
  189. }
  190. // -----------------------------  End  ----------------------------------
  191.  
  192.  
  193. // **********************************************************************
  194. // *    Function to parse the cookie and extract the ordered            *
  195. // *        items from the string. This in turn triggers the            *
  196. // *    writeCart() function to display the shopping cart.              *
  197. // **********************************************************************
  198.  
  199.  
  200. function DetailsStored() {
  201.  
  202. //addDetail = '' + Salute + '¼' + FirstName 
  203. //+ '║' + Initials + '╗' + LastName + '┐' + CompName + '╢' + Address + '▐' + Address2 
  204. //+ ' ' + PoCode + '°' +  CustTele
  205.  
  206.  
  207. if (getCookieData("Detail")) {
  208.  substr0 = getCookieData("Detail")
  209.  cLen = substr0.length
  210.  offset0 = substr0.indexOf("@")
  211.  counter = substr0.substring(0,offset0)
  212.  
  213.  j = 0
  214.   for (i=1; i<=counter; i++) {
  215.   offsetq = eval('offset' + j + '');
  216.   substrq = eval('substr' + j + '');
  217.  
  218.   eval('ind' + i + ' = offsetq + 1');
  219.   eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
  220.   eval('offset' + i + ' = substr' + i + '.indexOf("^")');
  221.   eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
  222.  
  223.   // Salutation
  224.   eval('SalutInd' + i + ' = item' + i + '.indexOf("¼")');
  225.   eval('Salut' + i + ' = item' + i + '.substring(0,SalutInd' + i + ')');
  226.  
  227.  // First Name
  228.   eval('FirstInd' + i + ' = item' + i + '.indexOf("║")');
  229.   eval('FirstNam' + i + ' = item' + i + '.substring((SalutInd' + i + ' + 1),FirstInd' + i + ')');
  230.  
  231.  // Initials
  232.   eval('InitialInd' + i + ' = item' + i + '.indexOf("╗")');
  233.   eval('Initials' + i + ' = item' + i + '.substring((FirstInd' + i + ' + 1),InitialInd' + i + ')');
  234.   
  235. // Last Name
  236.   eval('LastNamInd' + i + ' = item' + i + '.indexOf("┐")');
  237.   eval('LastNam' + i + ' = item' + i + '.substring((InitialInd' + i + ' + 1),LastNamInd' + i + ')'); 
  238.  
  239. // Company Name
  240.   eval('CompNamInd' + i + ' = item' + i + '.indexOf("╢")');
  241.   eval('CompNam' + i + ' = item' + i + '.substring((LastNamInd' + i + ' + 1),CompNamInd' + i + ')'); 
  242.  
  243. // Address
  244.   eval('AddInd' + i + ' = item' + i + '.indexOf("▐")');
  245.   eval('Add' + i + ' = item' + i + '.substring((CompNamInd' + i + ' + 1),AddInd' + i + ')'); 
  246.  
  247. // Address2
  248.   eval('Add2Ind' + i + ' = item' + i + '.indexOf(" ")');
  249.   eval('Add2' + i + ' = item' + i + '.substring((AddInd' + i + ' + 1),Add2Ind' + i + ')'); 
  250.  
  251. // Postal Code
  252.   eval('PoCdeInd' + i + ' = item' + i + '.indexOf("°")');
  253.   eval('PoCde' + i + ' = item' + i + '.substring((Add2Ind' + i + ' + 1),PoCdeInd' + i + ')'); 
  254.  
  255.   // Telephone
  256.   eval('CustTel' + i + ' = item' + i + '.substring((PoCdeInd' + i + ' + 1),offset' + i + ')'); 
  257.   eval('orderDetail(i,Salut' + i + ',FirstNam' + i + ',Initials' + i + ',LastNam' + i +',CompNam' + i + ',Add' + i +',Add2' + i +',PoCde' + i +',CustTel' + i +')');
  258.  
  259. j++
  260.  
  261.  }
  262.  WriteDetails();
  263.  }
  264. }
  265.  
  266. // ------------------------  End Cookie Reader ------------------
  267.  
  268. //                   ----====**** $$$ ****====----
  269.  
  270.  
  271. //     ----====**** End Customer Detail cookie code. ****====----
  272.  
  273. // **********************************************************************
  274. // *                Function to Print the Detail Form                     *
  275. // **********************************************************************
  276.  
  277. function WriteDetails() {
  278. Ndx = 1
  279.  document.write('<FORM NAME="Detail"> '
  280.  +  '        <TABLE WIDTH="466" BORDER="1" BORDERCOLOR="#000096" CELLSPACING="0"'
  281.  +  '         CELLPADDING="0" BGCOLOR="#000096"> '
  282.  +  '          <TR> '
  283.  +  '             <TD><B><FONT COLOR="#FFFFCC" FACE="Verdana,Arial,Helvetica"'
  284.  +  '                SIZE="2">Customer Details</FONT></B></TD> '
  285.  +  '             <TD><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  286.  +  '                COLOR="#FFFFCC"><B>Customer / Account Address</B></FONT></TD> '
  287.  +  '          </TR> '
  288.  +  '        </TABLE> '
  289.  +  '        <TABLE WIDTH="450" BORDER="0" CELLSPACING="0" CELLPADDING="0"'
  290.  +  '         BGCOLOR="#FFFFFF"> '
  291.  +  '          <TR> '
  292.  +  '             <TD ALIGN="CENTER"> <FONT FACE="verdana" SIZE="1">Please enter your'
  293.  +  '                details below.</FONT> </TD> '
  294.  +  '          </TR> '
  295.  +  '        </TABLE> '
  296.  +  '        <BR> '
  297.  +  '        <TABLE WIDTH="466" BGCOLOR="#FFFFFF" BORDER="1" BORDERCOLOR="#000000"'
  298.  +  '         CELLPADDING="0" CELLSPACING="0"> '
  299.  +  '          <TR> '
  300.  +  '             <TD HEIGHT="5" ALIGN="CENTER"> '
  301.  +  '                <TABLE WIDTH="100%" BORDER="0" CELLPADDING="1" CELLSPACING="0"> '
  302.  +  '                  <TR VALIGN="MIDDLE">'
  303.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  304.  +  '                      BGCOLOR="#000096"> </TD>'
  305.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  306.  +  '                      BGCOLOR="#FEF0D8"> </TD>'
  307.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  308.  +  '                      BGCOLOR="#FEF0D8"> </TD>'
  309.  +  '                  </TR>'
  310.  +  '                  <TR VALIGN="MIDDLE"> '
  311.  +  '                 <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  312.  +  '                  BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  313.  +  '                        COLOR="#FFFFCC">Mr/ Mrs Miss/ Ms.</FONT></B></TD> '
  314.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  315.  +  '                  BGCOLOR="#FEF0D8"></TD> '
  316.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  317.  +  '                  BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text9"'
  318.  +  '                        SIZE="4" MAXLENGTH="4" VALUE="' + Salute[Ndx] + '"></FONT></TD> '
  319.  +  '              </TR> '
  320.  +  '                  <TR VALIGN="MIDDLE"> '
  321.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  322.  +  '                      BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  323.  +  '                        COLOR="#FFFFCC">First Name</FONT></B></TD> '
  324.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  325.  +  '                      BGCOLOR="#FEF0D8"></TD> '
  326.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  327.  +  '                      BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text1"'
  328.  +  '                        VALUE="' + FirstName[Ndx] + '"></FONT></TD> '
  329.  +  '                  </TR> '
  330.  +  '                  <TR VALIGN="MIDDLE"> '
  331.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  332.  +  '                      BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  333.  +  '                        COLOR="#FFFFCC">Initials</FONT></B></TD> '
  334.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  335.  +  '                      BGCOLOR="#FEF0D8"></TD> '
  336.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  337.  +  '                      BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text2"'
  338.  +  '                        SIZE="5" MAXLENGTH="10" VALUE="' + Initials[Ndx] + '"></FONT></TD> '
  339.  +  '                  </TR> '
  340.  +  '                  <TR> '
  341.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  342.  +  '                      BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  343.  +  '                        COLOR="#FFFFCC">Last Name</FONT></B></TD> '
  344.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  345.  +  '                      BGCOLOR="#FEF0D8"></TD> '
  346.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  347.  +  '                      BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text3"'
  348.  +  '                        SIZE="35" MAXLENGTH="35" VALUE="' + LastName[Ndx]+ '"></FONT></TD> '
  349.  +  '                  </TR> '
  350.  +  '                  <TR> '
  351.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  352.  +  '                      BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  353.  +  '                        COLOR="#FFFFCC">Company Name</FONT></B></TD> '
  354.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  355.  +  '                      BGCOLOR="#FEF0D8"></TD> '
  356.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  357.  +  '                      BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text4"'
  358.  +  '                        SIZE="35" MAXLENGTH="35" VALUE="' + CompName[Ndx] + '"></FONT></TD> '
  359.  +  '                  </TR> '
  360.  +  '                  <TR VALIGN="MIDDLE"> '
  361.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  362.  +  '                      BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  363.  +  '                        COLOR="#FFFFCC">Address</FONT></B></TD> '
  364.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  365.  +  '                      BGCOLOR="#FEF0D8"></TD> '
  366.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  367.  +  '                      BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text5"'
  368.  +  '                        SIZE="35" MAXLENGTH="35" VALUE="' + Address[Ndx] + '"></FONT></TD> '
  369.  +  '                  </TR> '
  370.  +  '                  <TR> '
  371.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  372.  +  '                      BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  373.  +  '                        COLOR="#FFFFCC">Address2</FONT></B></TD> '
  374.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  375.  +  '                      BGCOLOR="#FEF0D8"></TD> '
  376.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  377.  +  '                      BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text6"'
  378.  +  '                        VALUE="' + Address2[Ndx] + '" SIZE="20" MAXLENGTH="30"></FONT></TD> '
  379.  +  '                  </TR> '
  380.  +  '                  <TR> '
  381.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  382.  +  '                      BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  383.  +  '                        COLOR="#FFFFCC">Postcode</FONT></B></TD> '
  384.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  385.  +  '                      BGCOLOR="#FEF0D8"></TD> '
  386.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  387.  +  '                      BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text7"'
  388.  +  '                        SIZE="8" MAXLENGTH="8" VALUE="' + PoCode[Ndx] + '"></FONT></TD> '
  389.  +  '                  </TR> '
  390.  +  '                  <TR VALIGN="MIDDLE"> '
  391.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  392.  +  '                      BGCOLOR="#000096"><B><FONT FACE="verdana,Arial,helvetica" SIZE="1"'
  393.  +  '                        COLOR="#FFFFCC">Telephone</FONT></B></TD> '
  394.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  395.  +  '                      BGCOLOR="#FEF0D8"></TD> '
  396.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  397.  +  '                      BGCOLOR="#FEF0D8"><FONT COLOR="#FFFFCC"><INPUT TYPE="TEXT" NAME="Text8"'
  398.  +  '                        SIZE="35" MAXLENGTH="35" VALUE="' + CustTele[Ndx]+ '"></FONT></TD> '
  399.  +  '                  </TR> '
  400.  +  '                  <TR> '
  401.  +  '                     <TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE"'
  402.  +  '                      BGCOLOR="#000096"> </TD> '
  403.  +  '                     <TD WIDTH="9" ALIGN="LEFT" VALIGN="MIDDLE"'
  404.  +  '                      BGCOLOR="#FEF0D8"> </TD> '
  405.  +  '                     <TD WIDTH="296" ALIGN="LEFT" VALIGN="MIDDLE"'
  406.  +  '                      BGCOLOR="#FEF0D8"> </TD> '
  407.  +  '                  </TR> '
  408.  +  '                </TABLE> </TD> '
  409.  +  '          </TR> '
  410.  +  '        </TABLE></FORM>');
  411.    document.close();
  412. }
  413.